﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_MoveUpJump]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_MoveUpJump];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_MoveUpJump]
    @FlowID int,
    @StepID int,
    @Priority int
AS
IF @Priority>1 
BEGIN
    UPDATE uds_flow_jump
        SET Priority = -1
        WHERE     flow_id = @flowid
            and step_id = @StepID
            and priority = @Priority-1

    UPDATE uds_flow_jump
        SET Priority = Priority -1
        WHERE     flow_id = @flowid
            and step_id = @StepID
            and priority = @Priority 

    UPDATE uds_flow_jump
        SET Priority = @Priority 
        WHERE     flow_id = @flowid
            and step_id = @StepID
            and priority = -1

    RETURN 0
END
ELSE
    RETURN 1